Imports cmplib01

Public Class frmElementManager
    Inherits System.Windows.Forms.Form

    Private ptrGameData As CampaignerGameData
    Private ptrGroundChit As ChitUnitTypeMember
    Private InitialPV As Boolean

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents pnlExistingElements As System.Windows.Forms.Panel
    Friend WithEvents lvwExistingElements As System.Windows.Forms.ListView
    Friend WithEvents colCount As System.Windows.Forms.ColumnHeader
    Friend WithEvents colElementName As System.Windows.Forms.ColumnHeader
    Friend WithEvents pnlAddElements As System.Windows.Forms.Panel
    Friend WithEvents btnRemoveElement As System.Windows.Forms.Button
    Friend WithEvents btnAddElement As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents numRemoveCount As System.Windows.Forms.NumericUpDown
    Friend WithEvents numAddCount As System.Windows.Forms.NumericUpDown
    Friend WithEvents cboElementClass As System.Windows.Forms.ComboBox
    Friend WithEvents lstElements As System.Windows.Forms.ListBox
    Friend WithEvents lstOptionsForSelectedElement As System.Windows.Forms.ListBox
    Friend WithEvents lblElements As System.Windows.Forms.Label
    Friend WithEvents lblOptionsInSelectedElement As System.Windows.Forms.Label
    Friend WithEvents lblAddElement As System.Windows.Forms.Label
    Friend WithEvents tvwElementOptionTypes As System.Windows.Forms.TreeView
    Friend WithEvents chkAddOptions As System.Windows.Forms.CheckBox
    Friend WithEvents btnRemoveElementOption As System.Windows.Forms.Button
    Friend WithEvents lstGroups As System.Windows.Forms.ListBox
    Friend WithEvents btnDeleteGroup As System.Windows.Forms.Button
    Friend WithEvents btnAddGroup As System.Windows.Forms.Button
    Friend WithEvents lblElementGroups As System.Windows.Forms.Label
    Friend WithEvents pgdElementGroupProperties As System.Windows.Forms.PropertyGrid
    Friend WithEvents btnViewAll As System.Windows.Forms.Button
    Friend WithEvents lblElementCost As System.Windows.Forms.Label
    Friend WithEvents colCostEach As System.Windows.Forms.ColumnHeader
    Friend WithEvents colTotalCost As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmElementManager))
        Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"30", "Infantry Troop"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"6", "Heavy Weapon"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"4", "Light Tank"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim TreeNode1 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Frag Grenades")
        Dim TreeNode2 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Krak Grenades")
        Dim TreeNode3 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Boltgun")
        Dim TreeNode4 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Dreadnought Assault Cannon")
        Me.pnlTopBorder = New System.Windows.Forms.Panel
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox
        Me.txtTitleBox = New System.Windows.Forms.TextBox
        Me.pnlExistingElements = New System.Windows.Forms.Panel
        Me.btnViewAll = New System.Windows.Forms.Button
        Me.lblElementGroups = New System.Windows.Forms.Label
        Me.btnAddGroup = New System.Windows.Forms.Button
        Me.btnDeleteGroup = New System.Windows.Forms.Button
        Me.lstGroups = New System.Windows.Forms.ListBox
        Me.lblOptionsInSelectedElement = New System.Windows.Forms.Label
        Me.lblElements = New System.Windows.Forms.Label
        Me.btnRemoveElementOption = New System.Windows.Forms.Button
        Me.lstOptionsForSelectedElement = New System.Windows.Forms.ListBox
        Me.btnRemoveElement = New System.Windows.Forms.Button
        Me.numRemoveCount = New System.Windows.Forms.NumericUpDown
        Me.lvwExistingElements = New System.Windows.Forms.ListView
        Me.colCount = New System.Windows.Forms.ColumnHeader
        Me.colElementName = New System.Windows.Forms.ColumnHeader
        Me.colCostEach = New System.Windows.Forms.ColumnHeader
        Me.colTotalCost = New System.Windows.Forms.ColumnHeader
        Me.pgdElementGroupProperties = New System.Windows.Forms.PropertyGrid
        Me.pnlAddElements = New System.Windows.Forms.Panel
        Me.tvwElementOptionTypes = New System.Windows.Forms.TreeView
        Me.lblAddElement = New System.Windows.Forms.Label
        Me.chkAddOptions = New System.Windows.Forms.CheckBox
        Me.btnAddElement = New System.Windows.Forms.Button
        Me.numAddCount = New System.Windows.Forms.NumericUpDown
        Me.cboElementClass = New System.Windows.Forms.ComboBox
        Me.lstElements = New System.Windows.Forms.ListBox
        Me.lblElementCost = New System.Windows.Forms.Label
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlTopBorder.SuspendLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.pnlExistingElements.SuspendLayout()
        CType(Me.numRemoveCount, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.pnlAddElements.SuspendLayout()
        CType(Me.numAddCount, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.Add(Me.picCampaignerIcon)
        Me.pnlTopBorder.Controls.Add(Me.txtTitleBox)
        Me.pnlTopBorder.Location = New System.Drawing.Point(-1, 8)
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(698, 40)
        Me.pnlTopBorder.TabIndex = 18
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.Image = CType(resources.GetObject("picCampaignerIcon.Image"), System.Drawing.Image)
        Me.picCampaignerIcon.Location = New System.Drawing.Point(9, 11)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(16, 16)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(32, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(312, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "Campaigner [Element Manager]"
        '
        'pnlExistingElements
        '
        Me.pnlExistingElements.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlExistingElements.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlExistingElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlExistingElements.Controls.Add(Me.btnViewAll)
        Me.pnlExistingElements.Controls.Add(Me.lblElementGroups)
        Me.pnlExistingElements.Controls.Add(Me.btnAddGroup)
        Me.pnlExistingElements.Controls.Add(Me.btnDeleteGroup)
        Me.pnlExistingElements.Controls.Add(Me.lstGroups)
        Me.pnlExistingElements.Controls.Add(Me.lblOptionsInSelectedElement)
        Me.pnlExistingElements.Controls.Add(Me.lblElements)
        Me.pnlExistingElements.Controls.Add(Me.btnRemoveElementOption)
        Me.pnlExistingElements.Controls.Add(Me.lstOptionsForSelectedElement)
        Me.pnlExistingElements.Controls.Add(Me.btnRemoveElement)
        Me.pnlExistingElements.Controls.Add(Me.numRemoveCount)
        Me.pnlExistingElements.Controls.Add(Me.lvwExistingElements)
        Me.pnlExistingElements.Controls.Add(Me.pgdElementGroupProperties)
        Me.pnlExistingElements.Location = New System.Drawing.Point(211, 56)
        Me.pnlExistingElements.Name = "pnlExistingElements"
        Me.pnlExistingElements.Size = New System.Drawing.Size(482, 384)
        Me.pnlExistingElements.TabIndex = 20
        '
        'btnViewAll
        '
        Me.btnViewAll.BackColor = System.Drawing.Color.LightBlue
        Me.btnViewAll.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnViewAll.Location = New System.Drawing.Point(16, 358)
        Me.btnViewAll.Name = "btnViewAll"
        Me.btnViewAll.Size = New System.Drawing.Size(160, 20)
        Me.btnViewAll.TabIndex = 33
        Me.btnViewAll.Text = "View All Elements In Groups"
        Me.btnViewAll.UseVisualStyleBackColor = False
        '
        'lblElementGroups
        '
        Me.lblElementGroups.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblElementGroups.Location = New System.Drawing.Point(11, 4)
        Me.lblElementGroups.Name = "lblElementGroups"
        Me.lblElementGroups.Size = New System.Drawing.Size(136, 16)
        Me.lblElementGroups.TabIndex = 31
        Me.lblElementGroups.Text = "Elements in this chit"
        '
        'btnAddGroup
        '
        Me.btnAddGroup.BackColor = System.Drawing.Color.LightBlue
        Me.btnAddGroup.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAddGroup.Location = New System.Drawing.Point(11, 328)
        Me.btnAddGroup.Name = "btnAddGroup"
        Me.btnAddGroup.Size = New System.Drawing.Size(75, 20)
        Me.btnAddGroup.TabIndex = 30
        Me.btnAddGroup.Text = "Add Group"
        Me.btnAddGroup.UseVisualStyleBackColor = False
        '
        'btnDeleteGroup
        '
        Me.btnDeleteGroup.BackColor = System.Drawing.Color.LightBlue
        Me.btnDeleteGroup.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteGroup.Location = New System.Drawing.Point(104, 328)
        Me.btnDeleteGroup.Name = "btnDeleteGroup"
        Me.btnDeleteGroup.Size = New System.Drawing.Size(75, 20)
        Me.btnDeleteGroup.TabIndex = 29
        Me.btnDeleteGroup.Text = "Remove"
        Me.btnDeleteGroup.UseVisualStyleBackColor = False
        '
        'lstGroups
        '
        Me.lstGroups.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstGroups.Items.AddRange(New Object() {"<Ungrouped>"})
        Me.lstGroups.Location = New System.Drawing.Point(8, 24)
        Me.lstGroups.Name = "lstGroups"
        Me.lstGroups.Size = New System.Drawing.Size(176, 301)
        Me.lstGroups.TabIndex = 28
        '
        'lblOptionsInSelectedElement
        '
        Me.lblOptionsInSelectedElement.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblOptionsInSelectedElement.Location = New System.Drawing.Point(200, 236)
        Me.lblOptionsInSelectedElement.Name = "lblOptionsInSelectedElement"
        Me.lblOptionsInSelectedElement.Size = New System.Drawing.Size(160, 16)
        Me.lblOptionsInSelectedElement.TabIndex = 27
        Me.lblOptionsInSelectedElement.Text = "Options for selected element"
        '
        'lblElements
        '
        Me.lblElements.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblElements.Location = New System.Drawing.Point(200, 4)
        Me.lblElements.Name = "lblElements"
        Me.lblElements.Size = New System.Drawing.Size(136, 16)
        Me.lblElements.TabIndex = 26
        Me.lblElements.Text = "Elements in this chit"
        '
        'btnRemoveElementOption
        '
        Me.btnRemoveElementOption.BackColor = System.Drawing.Color.LightBlue
        Me.btnRemoveElementOption.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnRemoveElementOption.Location = New System.Drawing.Point(401, 357)
        Me.btnRemoveElementOption.Name = "btnRemoveElementOption"
        Me.btnRemoveElementOption.Size = New System.Drawing.Size(75, 20)
        Me.btnRemoveElementOption.TabIndex = 25
        Me.btnRemoveElementOption.Text = "Remove"
        Me.btnRemoveElementOption.UseVisualStyleBackColor = False
        '
        'lstOptionsForSelectedElement
        '
        Me.lstOptionsForSelectedElement.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstOptionsForSelectedElement.Location = New System.Drawing.Point(200, 258)
        Me.lstOptionsForSelectedElement.Name = "lstOptionsForSelectedElement"
        Me.lstOptionsForSelectedElement.Size = New System.Drawing.Size(276, 93)
        Me.lstOptionsForSelectedElement.TabIndex = 24
        '
        'btnRemoveElement
        '
        Me.btnRemoveElement.BackColor = System.Drawing.Color.LightBlue
        Me.btnRemoveElement.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnRemoveElement.Location = New System.Drawing.Point(400, 204)
        Me.btnRemoveElement.Name = "btnRemoveElement"
        Me.btnRemoveElement.Size = New System.Drawing.Size(75, 20)
        Me.btnRemoveElement.TabIndex = 23
        Me.btnRemoveElement.Text = "Remove"
        Me.btnRemoveElement.UseVisualStyleBackColor = False
        '
        'numRemoveCount
        '
        Me.numRemoveCount.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numRemoveCount.Location = New System.Drawing.Point(312, 204)
        Me.numRemoveCount.Maximum = New Decimal(New Integer() {5250, 0, 0, 0})
        Me.numRemoveCount.Minimum = New Decimal(New Integer() {1, 0, 0, 0})
        Me.numRemoveCount.Name = "numRemoveCount"
        Me.numRemoveCount.Size = New System.Drawing.Size(80, 20)
        Me.numRemoveCount.TabIndex = 22
        Me.numRemoveCount.Value = New Decimal(New Integer() {1, 0, 0, 0})
        '
        'lvwExistingElements
        '
        Me.lvwExistingElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lvwExistingElements.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colCount, Me.colElementName, Me.colCostEach, Me.colTotalCost})
        Me.lvwExistingElements.FullRowSelect = True
        Me.lvwExistingElements.GridLines = True
        Me.lvwExistingElements.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3})
        Me.lvwExistingElements.Location = New System.Drawing.Point(200, 24)
        Me.lvwExistingElements.MultiSelect = False
        Me.lvwExistingElements.Name = "lvwExistingElements"
        Me.lvwExistingElements.Size = New System.Drawing.Size(275, 172)
        Me.lvwExistingElements.TabIndex = 0
        Me.lvwExistingElements.UseCompatibleStateImageBehavior = False
        Me.lvwExistingElements.View = System.Windows.Forms.View.Details
        '
        'colCount
        '
        Me.colCount.Text = "Count"
        Me.colCount.Width = 40
        '
        'colElementName
        '
        Me.colElementName.Text = "Element Name"
        Me.colElementName.Width = 143
        '
        'colCostEach
        '
        Me.colCostEach.Text = "PVe"
        Me.colCostEach.Width = 40
        '
        'colTotalCost
        '
        Me.colTotalCost.Text = "PVt"
        Me.colTotalCost.Width = 32
        '
        'pgdElementGroupProperties
        '
        Me.pgdElementGroupProperties.CommandsBackColor = System.Drawing.Color.LightSkyBlue
        Me.pgdElementGroupProperties.LineColor = System.Drawing.SystemColors.ScrollBar
        Me.pgdElementGroupProperties.Location = New System.Drawing.Point(200, 208)
        Me.pgdElementGroupProperties.Name = "pgdElementGroupProperties"
        Me.pgdElementGroupProperties.Size = New System.Drawing.Size(176, 24)
        Me.pgdElementGroupProperties.TabIndex = 32
        Me.pgdElementGroupProperties.Visible = False
        '
        'pnlAddElements
        '
        Me.pnlAddElements.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlAddElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlAddElements.Controls.Add(Me.tvwElementOptionTypes)
        Me.pnlAddElements.Controls.Add(Me.lblAddElement)
        Me.pnlAddElements.Controls.Add(Me.chkAddOptions)
        Me.pnlAddElements.Controls.Add(Me.btnAddElement)
        Me.pnlAddElements.Controls.Add(Me.numAddCount)
        Me.pnlAddElements.Controls.Add(Me.cboElementClass)
        Me.pnlAddElements.Controls.Add(Me.lstElements)
        Me.pnlAddElements.Controls.Add(Me.lblElementCost)
        Me.pnlAddElements.Location = New System.Drawing.Point(5, 56)
        Me.pnlAddElements.Name = "pnlAddElements"
        Me.pnlAddElements.Size = New System.Drawing.Size(200, 384)
        Me.pnlAddElements.TabIndex = 19
        '
        'tvwElementOptionTypes
        '
        Me.tvwElementOptionTypes.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwElementOptionTypes.CheckBoxes = True
        Me.tvwElementOptionTypes.Location = New System.Drawing.Point(8, 264)
        Me.tvwElementOptionTypes.Name = "tvwElementOptionTypes"
        TreeNode1.Name = ""
        TreeNode1.Text = "Frag Grenades"
        TreeNode2.Name = ""
        TreeNode2.Text = "Krak Grenades"
        TreeNode3.Name = ""
        TreeNode3.Text = "Boltgun"
        TreeNode4.Name = ""
        TreeNode4.Text = "Dreadnought Assault Cannon"
        Me.tvwElementOptionTypes.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode1, TreeNode2, TreeNode3, TreeNode4})
        Me.tvwElementOptionTypes.ShowLines = False
        Me.tvwElementOptionTypes.ShowPlusMinus = False
        Me.tvwElementOptionTypes.ShowRootLines = False
        Me.tvwElementOptionTypes.Size = New System.Drawing.Size(184, 112)
        Me.tvwElementOptionTypes.TabIndex = 28
        '
        'lblAddElement
        '
        Me.lblAddElement.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAddElement.Location = New System.Drawing.Point(8, 4)
        Me.lblAddElement.Name = "lblAddElement"
        Me.lblAddElement.Size = New System.Drawing.Size(144, 16)
        Me.lblAddElement.TabIndex = 27
        Me.lblAddElement.Text = "Select Element Type to add"
        '
        'chkAddOptions
        '
        Me.chkAddOptions.Location = New System.Drawing.Point(8, 240)
        Me.chkAddOptions.Name = "chkAddOptions"
        Me.chkAddOptions.Size = New System.Drawing.Size(184, 16)
        Me.chkAddOptions.TabIndex = 26
        Me.chkAddOptions.Text = "Add Selected Options"
        '
        'btnAddElement
        '
        Me.btnAddElement.BackColor = System.Drawing.Color.LightBlue
        Me.btnAddElement.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAddElement.Location = New System.Drawing.Point(117, 176)
        Me.btnAddElement.Name = "btnAddElement"
        Me.btnAddElement.Size = New System.Drawing.Size(75, 20)
        Me.btnAddElement.TabIndex = 21
        Me.btnAddElement.Text = "Add >>"
        Me.btnAddElement.UseVisualStyleBackColor = False
        '
        'numAddCount
        '
        Me.numAddCount.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numAddCount.Location = New System.Drawing.Point(8, 176)
        Me.numAddCount.Minimum = New Decimal(New Integer() {1, 0, 0, 0})
        Me.numAddCount.Name = "numAddCount"
        Me.numAddCount.Size = New System.Drawing.Size(80, 20)
        Me.numAddCount.TabIndex = 2
        Me.numAddCount.Value = New Decimal(New Integer() {1, 0, 0, 0})
        '
        'cboElementClass
        '
        Me.cboElementClass.Location = New System.Drawing.Point(8, 24)
        Me.cboElementClass.Name = "cboElementClass"
        Me.cboElementClass.Size = New System.Drawing.Size(184, 21)
        Me.cboElementClass.TabIndex = 1
        Me.cboElementClass.Text = "(All Classes)"
        '
        'lstElements
        '
        Me.lstElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstElements.Items.AddRange(New Object() {"Infantry Troop", "Heavy Weapon", "Assault Weapon", "Armored Transport"})
        Me.lstElements.Location = New System.Drawing.Point(8, 48)
        Me.lstElements.Name = "lstElements"
        Me.lstElements.Size = New System.Drawing.Size(184, 119)
        Me.lstElements.TabIndex = 0
        '
        'lblElementCost
        '
        Me.lblElementCost.Location = New System.Drawing.Point(8, 208)
        Me.lblElementCost.Name = "lblElementCost"
        Me.lblElementCost.Size = New System.Drawing.Size(184, 16)
        Me.lblElementCost.TabIndex = 34
        Me.lblElementCost.Text = "Cost:"
        '
        'btnOK
        '
        Me.btnOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.ForeColor = System.Drawing.Color.Black
        Me.btnOK.Location = New System.Drawing.Point(610, 448)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 28
        Me.btnOK.Text = "OK"
        Me.btnOK.UseVisualStyleBackColor = False
        '
        'frmElementManager
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(698, 480)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlExistingElements)
        Me.Controls.Add(Me.pnlAddElements)
        Me.Controls.Add(Me.pnlTopBorder)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmElementManager"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Element Manager"
        Me.pnlTopBorder.ResumeLayout(False)
        Me.pnlTopBorder.PerformLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).EndInit()
        Me.pnlExistingElements.ResumeLayout(False)
        CType(Me.numRemoveCount, System.ComponentModel.ISupportInitialize).EndInit()
        Me.pnlAddElements.ResumeLayout(False)
        CType(Me.numAddCount, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef GameData As CampaignerGameData, ByRef Chit As ChitMember, Optional ByVal InitialPointValue As Boolean = False)
        ' the InitialPointValue parameter effects how the point value is calculated (in comparrison to the current and initial)
        Me.New()

        InitialPV = InitialPointValue
        ptrGameData = GameData
        ptrGroundChit = Chit

        ' populate existing choices
        PopulateAddPanel()
        PopulateChitsElements()
        PopulateExistingOptionTypes()
        ListGroups()

        lstGroups.SelectedIndex = 0

    End Sub

    Private Sub PopulateAddPanel()
        Dim ElClasso As ElementClass

        cboElementClass.Items.Clear()

        ' add each of the choices
        cboElementClass.Items.Add("(All Classes)")
        cboElementClass.Text = "(All Classes)"
        For Each ElClasso In ptrGameData.ElementMan.DefinedElementClasses
            cboElementClass.Items.Add(ElClasso)
        Next

        PopulateExistingElementTypes(cboElementClass.Text)

    End Sub

    Private Sub PopulateExistingElementTypes(Optional ByVal ofType As String = "(All Classes)")
        Dim elTypo As ElementType

        lstElements.Items.Clear()

        For Each elTypo In ptrGameData.ElementMan.DefinedElementTypes
            If ofType = "(All Classes)" Then
                lstElements.Items.Add(elTypo)
            Else
                If elTypo.ElementClassName = ofType Then
                    lstElements.Items.Add(elTypo)
                End If
            End If
        Next
    End Sub

    Private Sub PopulateExistingOptionTypes(Optional ByVal ofType As String = "(All Classes)")
        Dim opto As ElementOptionType

        Try
            tvwElementOptionTypes.Nodes.Clear()
        Catch

        End Try

        For Each opto In ptrGameData.ElementMan.DefinedElementOptions
            If ofType = "(All Classes)" Then
                Dim nod As New TreeNode(opto.ElementOptionTypeName)
                tvwElementOptionTypes.Nodes.Add(nod)
            Else
                If opto.ElementClassName = ofType Then
                    Dim nod As New TreeNode(opto.ElementOptionTypeName)
                    tvwElementOptionTypes.Nodes.Add(nod)
                End If
            End If
        Next

    End Sub

    Private Sub cboElementClass_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboElementClass.SelectedIndexChanged
        PopulateExistingElementTypes(cboElementClass.Text)
        PopulateExistingOptionTypes(cboElementClass.Text)
    End Sub

    Private Sub btnAddElement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddElement.Click
        If Not lstElements.SelectedItem Is Nothing Then
            AddElement(lstElements.SelectedItem, numAddCount.Value)
        Else
            MessageBox.Show("Select an element type from the list above.", "Select Element Type", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub btnRemoveElement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveElement.Click

        Try
            If Not lvwExistingElements.SelectedItems(0) Is Nothing Then
                ' get the name of the selected guy
                Dim listi As ListViewItem = lvwExistingElements.SelectedItems(0)
                Dim Ele As Element = lvwExistingElements.SelectedItems(0).Tag

                ReduceCountOfElement(Ele, numRemoveCount.Value)
                PopulateChitsElements()
            End If
        Catch ex As Exception

        End Try

    End Sub

    Private Sub ReduceCountOfElement(ByVal Ele As Element, ByVal reduceCount As Integer)

        Ele.Count -= reduceCount

        'If Ele.Count < 1 Then ptrGroundChit.ChitElements.Remove(Ele)

    End Sub

    Private Sub PopulateChitsElements()
        ' list the count and type of elements this chit has.
        Try
            Dim Ele As GroupableElement

            lvwExistingElements.Items.Clear()

            If lstGroups.SelectedItem Is Nothing Then lstGroups.SelectedItem = lstGroups.Items.Item(0)

            For Each Ele In ptrGroundChit.elements
                If Ele.GroupName = Me.lstGroups.SelectedItem.ToString Then
                    ' show the count, and the type in the listview
                    Dim listI As New ListViewItem(Ele.Count)
                    ' use the tag to hold the element so we can get to it.
                    listI.Tag = Ele
                    listI.SubItems.Add(Ele.ElementTypeName)
                    ' Add the element to the tag. This makes it easy to muck with.
                    listI.SubItems.Add(Ele.ElementBaseCost)
                    listI.SubItems.Add(Ele.TotalCost)
                    listI.Tag = Ele
                    lvwExistingElements.Items.Add(listI)
                End If
            Next
        Catch ex As Exception
            HandleException("frmElementManager.PopulateChitsElements", ex)
        End Try

    End Sub

    Private Sub AddElement(ByVal elTypo As ElementType, ByVal count As Integer)
        ' if the element type already exists, add the count to the existing one.
        Dim ele As Element
        Dim bPreexisting As Boolean
        Dim newEle As New GroupableElement

        '// determine the group, if nothing is selected, select the primary group
        If lstGroups.SelectedItem Is Nothing Then lstGroups.SelectedItem = lstGroups.Items.Item(0)

        Dim group As ElementGroup = lstGroups.SelectedItem

        newEle.GroupName = group.GroupName

        newEle.Count = count
        newEle.Description = elTypo.ElementDescription
        newEle.ElementTypeName = elTypo.ElementTypeName
        newEle.ElementBaseCost = elTypo.ElementPointValue
        ' check the element options
        If chkAddOptions.Checked Then ApplyOptionsToElement(newEle)

        'ptrGroundChit.ChitElements.Add(newEle)

        PopulateChitsElements()

    End Sub

    Private Sub ApplyOptionsToElement(ByRef newEle As Element)
        Dim nod As TreeNode

        For Each nod In tvwElementOptionTypes.Nodes
            If nod.Checked Then
                Dim opto As ElementOptionType
                For Each opto In ptrGameData.ElementMan.DefinedElementOptions
                    If opto.ElementOptionTypeName = nod.Text Then
                        ' add this element option to the provided element. Yeah man.
                        Dim ElOpt As New ElementOption
                        ElOpt.ElementOptionClassName = opto.ElementClassName
                        ElOpt.ElementOptionCount = 1 ' default to 1
                        ElOpt.ElementOptionPointCost = opto.ElementPointCost
                        ElOpt.ElementOptionTypeName = opto.ElementOptionTypeName
                        newEle.Options.Add(ElOpt)
                        Exit For
                    End If
                Next
            End If
        Next

    End Sub

    Private Sub RemoveElement(ByVal elTypo As ElementType, ByVal count As Integer)
        Dim ele As Element

        Try
            'For Each ele In ptrGroundChit.elements
            '    If ele.ElementTypeName = elTypo.ElementTypeName Then
            '        ' remove the shit
            '        ele.Count -= count
            '        If ele.Count <= 0 Then ptrGroundChit.elements.Remove(ele)
            '        PopulateChitsElements()
            '        Exit For
            '    End If
            'Next
        Catch ex As Exception

        End Try

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Not InitialPV Then
            ' this is where we reassign the point value to the current point value. Yay!
            SetCurrentPointValue()
        End If
        Me.Hide()
    End Sub

    Private Sub SetCurrentPointValue()
        Dim ele As Element
        Dim pv As Integer

        For Each ele In ptrGroundChit.elements
            pv += ele.TotalCost
        Next

        'ptrGroundChit.CurrentPointValue = pv

    End Sub

    Private Sub lvwExistingElements_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwExistingElements.SelectedIndexChanged
        SelectElement()
    End Sub

    Private Sub SelectElement()
        Try
            If Not lvwExistingElements.SelectedItems Is Nothing Then
                ' we populate this element's options

                Dim ele As Element = lvwExistingElements.SelectedItems(0).Tag
                PopulateElementsOptions(ele)

            Else
                lstOptionsForSelectedElement.Items.Clear()
            End If
        Catch outta As ArgumentOutOfRangeException
            lstOptionsForSelectedElement.Items.Clear()
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub PopulateElementsOptions(ByRef ele As Element)
        lstOptionsForSelectedElement.Items.Clear()
        Dim opto As ElementOption
        For Each opto In ele.Options
            lstOptionsForSelectedElement.Items.Add(opto)
        Next
    End Sub

    Private Sub btnRemoveElementOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveElementOption.Click
        If Not lstOptionsForSelectedElement.SelectedItem Is Nothing Then
            Dim elnamo As String
            Dim opnamo As String

            Try
                elnamo = lvwExistingElements.SelectedItems(0).SubItems(1).Text
                opnamo = lstOptionsForSelectedElement.SelectedItem.ToString
                RemoveSelectedOptionFromElement(elnamo, opnamo)
            Catch ex As Exception
                HandleException(c_Module, ex)
            End Try
        End If
    End Sub

    Private Sub RemoveSelectedOptionFromElement(ByVal elementName As String, ByVal optionName As String)
        Dim Ele As Element
        Dim opto As ElementOption

        If lvwExistingElements.SelectedItems.Count = 0 Then Exit Sub

        Try
            Ele = lvwExistingElements.SelectedItems(0).Tag

            For Each opto In Ele.Options
                If opto.ElementOptionTypeName = optionName Then
                    Ele.Options.remove(opto)
                    SelectElement()
                    Exit Sub
                End If
            Next

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub btnAddGroup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddGroup.Click
        Dim fGenericEntry As New frmBasicEntry("Enter Group Name", "[a-zA-Z_0-9]")

        fGenericEntry.ShowDialog()
        If fGenericEntry.Cancelled = True Then Exit Sub

        AddElementGroup(fGenericEntry.Data)
    End Sub


    Private Sub AddElementGroup(ByVal GroupName As String)
        Try
            'Dim gah As New ElementGroup

            'If Not TypeOf ptrGroundChit.elements Is GroupableElements Then
            '    '// convert
            '    ConvertToGroupable()
            'End If

            '' add the new
            'gah.GroupName = GroupName
            'Dim Group As GroupableElements = ptrGroundChit.elements
            'Group.Groups.Add(gah)

            '' listgroups
            'ListGroups()
        Catch ex As Exception
            HandleException("frmElementManager.AddElementGroup", ex)
        End Try

    End Sub

    Private Sub ConvertToGroupable()
        Try
            'Dim tPower As New GroupableElements

            'tPower = tPower.ConvertToGroupable(ptrGroundChit.elements)
            'ptrGroundChit.elements = tPower
        Catch ex As Exception
            HandleException("frmElementManager.ConverToGroupable", ex)
        End Try
    End Sub

    Private Sub ListGroups()
        Try
            'lstGroups.Items.Clear()

            'If Not TypeOf ptrGroundChit.elements Is GroupableElements Then
            '    ConvertToGroupable()
            'End If

            'Dim Group As ElementGroup
            'Dim Groupies As GroupableElements = ptrGroundChit.elements

            '' add the default, no group
            'Dim shaddap As New ElementGroup
            'shaddap.GroupName = "<Ungrouped>"
            'shaddap.GroupPV = 0
            'shaddap.UseGroupPV = False

            'lstGroups.Items.Add(shaddap)

            'For Each Group In Groupies.Groups
            '    lstGroups.Items.Add(Group)
            'Next

        Catch ex As Exception
            HandleException("frmElementManager.ListGroups", ex)
        End Try

    End Sub


    Private Sub lstGroups_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstGroups.SelectedIndexChanged
        If lstGroups.SelectedItem Is Nothing Then Exit Sub

        Try
            pgdElementGroupProperties.SelectedObject = lstGroups.SelectedItem
            '// show elements only for selected group
            PopulateChitsElements()
        Catch ex As Exception
            HandleException("lstGroups.SelectedIndexChanged", ex)
        End Try

    End Sub

    Private Sub btnViewAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewAll.Click
        Dim fChit As New frmChitTreeHierarchy
        fChit.ShowDialog(ptrGroundChit)

    End Sub

    Private Sub btnDeleteGroup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteGroup.Click
        If lstGroups.SelectedItem Is Nothing Then Exit Sub
        If lstGroups.SelectedItem.ToString.Equals("<Ungrouped>") Then Exit Sub

        Dim deathGroup As ElementGroup = lstGroups.SelectedItem
        DeleteGroup(deathGroup)

    End Sub

    Private Sub DeleteGroup(ByRef Group As ElementGroup)

        Try
            Dim oldName As String = Group.GroupName
            Dim groupEle As GroupableElement

            For Each groupEle In ptrGroundChit.elements
                If groupEle.GroupName = oldName Then groupEle.GroupName = "<Ungrouped>"
            Next

            'Dim gche As GroupableElements = ptrGroundChit.elements
            'gche.Groups.Remove(Group)

            ListGroups()
            lstGroups.SelectedItem = lstGroups.Items.Item(0)
        Catch ex As Exception
            HandleException("frmElementManager.DeleteGroup", ex)
        End Try

    End Sub

    Private Sub lstElements_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstElements.SelectedIndexChanged
        CalculateCost()
    End Sub

    Private Sub CalculateCost()
        Dim eleType As ElementType
        Dim baseCost As Integer

        Try
            eleType = lstElements.SelectedItem
            baseCost = eleType.ElementPointValue
            baseCost *= numAddCount.Value
            lblElementCost.Text = "Cost: " & baseCost
        Catch ex As Exception

        End Try

    End Sub

    Private Sub numAddCount_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numAddCount.ValueChanged
        CalculateCost()
    End Sub
End Class

